package org.domain.demo.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import org.domain.demo.entity.Users;
import org.jboss.seam.annotations.Name;

@Name("usersDAO")
public class UsersDAO {
    
    @SuppressWarnings("unchecked")
	public Users findUsersByUserName(String principal,EntityManager entityManager) {
    	String hql = "Select Users from Users users where users.principal = :principal";
    	Query query = entityManager.createQuery(hql);
    	query.setParameter("principal", principal);
    	List<Users> result = query.getResultList();
    	if(result.size()>0){
    		return (Users)result.get(0);
    	}else{
    		return null;
    	}
    }
    
}
